package cn.lxh.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
// 扫描Mybatis的mapper映射器
@MapperScan("cn.lxh.mapper")
public class MybatisPlusConfig {

    // 分页插件配置对象, Mybatis-plus需要此配置对象 (会拦截分页查询请求, 自动帮助分页)
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    // 乐观锁插件 (会拦截写操作请求, 自动修改v = v + 1)
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }
}

